import { removeQuotes } from '../utils';
import { groupParser } from './group-parser';
import type { ICategoryItem, IColumn } from '../typings/index';

export function allFieldsParser(columns:string[]) {
  
  // 全部列数据
  const allColumns = columns.slice(1);

  // 分类列表
  const categoryList:Array<ICategoryItem> = [];

  // 自定义列数据
  const fieldsList:Array<IColumn> = [];

  // 关联字段
  const relationKeyMap = {};

  allColumns.forEach((item, index) => {
    const { categoryData, contentData } = groupParser(removeQuotes(item), index + 1);

    categoryList.push(categoryData);
    fieldsList.push(...contentData);
  });

  fieldsList.forEach((item) => {
    if (item.relationKey) {
      relationKeyMap[item.dataIndex] = item.relationKey;
    }
    delete item.relationKey;
  });

  return {
    categoryList,
    fieldsList,
    relationKeyMap,
  }
}